﻿namespace AgentJohnson.CodeAnnotations.Handlers
{
  using Resharper.Abstractions.CodeAnnotations;
  using Resharper.Abstractions.CodeDom;
  using Resharper.Abstractions.CodeDom.Accessors;
  using Resharper.Abstractions.Daemons;

  /// <summary>Defines the <see cref="NoPublicSetters"/> class.</summary>
  public class NoPublicSetters : ClassAnnotationHandler
  {
    #region Public Methods

    /// <summary>Processes the specified tree node.</summary>
    /// <param name="daemon">The daemon.</param>
    /// <param name="treeNode">The tree node.</param>
    public override void ProcessTreeNode(DaemonBase daemon, object treeNode)
    {
      var setter = Accessor.GetAccessor(treeNode);
      if (setter == null)
      {
        return;
      }

      if (!setter.IsSetter)
      {
        return;
      }

      var accessRights = setter.AccessRights;
      if (accessRights != AccessRights.Public)
      {
        return;
      }

      var highlight = daemon.CreateHighlight<ClassAnnotationHighlight>();

      highlight.ToolTip = "Public setters are not allowed for this class [Agent Johnson]";
      highlight.Range = setter.GetRange();
    }

    #endregion
  }
}